import 'package:flutter_axrjc/datasource/db/bean/MyLightBean.dart';
import 'package:flutter_axrjc/datasource/network/api/UserApi.dart';
import 'package:flutter_axrjc/util/IsarUtil.dart';
import 'package:isar/isar.dart';

class DBApi {
  static Future<void> deleteAll() async {
    var ids = isar.myLightBeans.where().findAllSync().map((e) => e.id).toList();
    await isar.writeTxnSync(() async {
      isar.myLightBeans.deleteAllSync(ids);
    });
  }

  static Future<void> putAll(List<myLightBean> list) async {
    await isar.writeTxn(() async {
      await isar.myLightBeans.putAll(list);
    });
  }

  static Future<List<myLightBean>> getAll() async {
    String telPhone = (await UserApi.getUser())?.customerInfo?.telPhone ?? "";
    return await isar.myLightBeans
        .filter()
        .userPhoneEqualTo(telPhone)
        .findAll();
  }
}
